/**
 * 组件库入口
 * */

import SXCText from './sxc-text'
import SXCWeather from './sxc-weather'
import SXCDateTimer from './sxc-date-timer'
import SXCButton from './sxc-button'
import SXCIframe from './sxc-iframe'
import SXCImage from './sxc-image'
import SXCVideo from './sxc-video'
import SXCAudio from './sxc-audio'
import SXCDoc from './sxc-document'
import SXCHDMI from './sxc-hdmi'
import SXCLive from './sxc-live'

// 所有组件列表
const components = [
  SXCText,
  SXCWeather,
  SXCDateTimer,
  SXCButton,
  SXCIframe,
  SXCImage,
  SXCVideo,
  SXCAudio,
  SXCDoc,
  SXCHDMI,
  SXCLive
]

// 定义 install 方法，接收 Vue 作为参数
const install = function (Vue) {
  // 判断是否安装，安装过就不继续往下执行
  if (install.installed) return
  install.installed = true
  // 遍历注册所有组件
  components.map(c => Vue.component(c.name, c))
}

// 检测到 Vue 才执行，毕竟我们是基于 Vue 的
if (typeof window !== 'undefined' && window.Vue) {
  install(window.Vue)
}

let registerComponents = {}
components.forEach(item => {
  registerComponents[item.name] = item
})

export {
  SXCText,
  SXCWeather,
  SXCDateTimer,
  SXCButton,
  SXCIframe,
  SXCImage,
  SXCVideo,
  SXCAudio,
  SXCDoc,
  SXCHDMI,
  SXCLive,
  registerComponents
}

export default {
  install
}
